home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Night of the Living Disc / Night of the Living Disc.hdv / Dev.CD.5 / Tools / Technical.Notes / IIGS / TN.IIGS.004 < prev    next >
Encoding:
Text File  |  1990-04-25  |  12.0 KB  |  264 lines  |  [04] ASCII Text (0x0000)

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. Apple IIgs
  7. #4:    Changing Graphics Modes in Mid-Application
  8.  
  9. Revised by:    C.K. Haun & Dan Oliver                                May 1990
  10. Written by:    Dan Oliver                                        October 1986
  11.  
  12. This Technical Note discusses how to switch between the two graphics modes, 
  13. 320 and 640 horizontal resolution, while running an application which uses the 
  14. Window, Control, and Menu Managers.
  15. Changes since November 1988:  Added desk accessory window closing information 
  16. and code.
  17. _____________________________________________________________________________
  18.  
  19. Why Change Resolution?
  20.  
  21. Why not?  There are certain applications where the ability to run in both 
  22. modes is essential; most graphics applications fall into this category.  Other 
  23. applications might switch modes to provide features which their competitors 
  24. lack; a financial application might display figures in 640 mode and charts in 
  25. 320 mode.  Still other applications may want to give the user the choice.  A 
  26. word processor might seem useful only in 640 mode, but what if the user wants 
  27. to print greeting cards with pictures?  The user does not need the line length 
  28. provided in 640 mode but does need the added color of 320 mode for the 
  29. pictures.
  30.  
  31. Let me preach a little.  I have worked on other machines with different 
  32. graphic modes and learned some things that might be of use to application 
  33. programmers.  Many application programmers fight mode switching with either 
  34. rhetoric or apathy, then when users expect their software to run in either 
  35. mode, they become frustrated when it does not allow switching.  To avoid the 
  36. problem of frustrating the user, you can provide mode switching (which is not 
  37. as hard as you might think).
  38.  
  39.  
  40. How To Change Modes
  41.  
  42. First, assume you are in an application which is running with a system menu 
  43. bar, a few visible windows with scroll bars, and one window with some standard 
  44. controls.  At some point, the user decides to change modes, possibly via a 
  45. menu item thoughtfully provided by the application programmer.  Your change 
  46. mode handler might look like the following:
  47.  
  48. ;
  49. ; --- This step is necessary if QuickDraw Auxiliary is started ---------------
  50.              _QDAuxShutDown     ;Shut down QDAux first
  51. ; ----------------------------------------------------------------------------
  52.              _QDShutdown        ;Shut down QuickDraw.
  53.                                 ;This will turn graphics off so you will see
  54.                                 ;the text screen for a second (a advertisement
  55.                                 ;might go here).
  56.              lda <mode          ;Variable that holds current resolution.
  57.              eor #$0080         ;Flip the mode bit, $0000 = 320, $0080 = 640.
  58.              sta <mode          ;New value will be used to start the new mode.
  59. ;
  60.              pei <QDzpage       ;Pass the direct pages allocated for QuickDraw.
  61.              pei <mode          ;New mode.
  62.              pei <QDwidth       ;0 for screen width; other numbers for printing
  63.              pei <MyID          ;Pass my ID number.
  64.              _QDStartup         ;Restart QuickDraw in the new mode.
  65. ;
  66.              _GrafOff           ;Turn screen off because changing mode
  67.                                 ;may not be pretty.
  68. ; --- This step is necessary if you need QuickDraw Auxiliary  ----------------
  69.              _QDAuxStartUp      ;Start QDAux again
  70. ; ----------------------------------------------------------------------------
  71. ;
  72. ;
  73. ; --- Fix up the cursor for the new mode -------------------------------------
  74. ;
  75.              pea 0              ;Pass minimum cursor X position.
  76.              lda #319           ;Maximum X position for 320 mode.
  77.              ldx <mode          ;320 or 640 mode?
  78.              beq store
  79.              lda #639           ;Maximum X position for 640 mode.
  80. store        pha                ;Pass maximum cursor X position.
  81.              pea 0              ;Pass minimum Y cursor position.
  82.              pea 199            ;Pass maximum Y cursor position.
  83.              _ClampMouse        ;Clamp the cursor to the new screen size.
  84. ;
  85.              _HomeMouse         ;Move the cursor to 0,0 to make sure
  86.                                 ;it is on screen.
  87.              _ShowCursor        ;Make cursor visible.
  88. ;
  89. ;
  90. ; --- Tell tools about the change --------------------------------------------
  91. ;
  92.              _WindNewRes        ;Tell Window Manager about the change.
  93.              _MenuNewRes        ;Tell Menu Manager about the change.
  94.              _CtlNewRes         ;Tell Control Manager about the change.
  95. ;
  96. ;
  97. ; --- Fix the screen to look good --------------------------------------------
  98. ;
  99. ;     Here you might want to change the color of the desktop, windows, menus or
  100. ;     controls to look good for the new mode.
  101. ;
  102. ;     See example below.
  103. ;
  104. ; --- Redraw the screen in the new mode --------------------------------------
  105. ;
  106.              pea 0              ;Pass flag to draw entire screen.
  107.              pea 0
  108.              _RefreshDesktop    ;Draw entire screen.
  109. ;
  110.              _GrafOn            ;Now show the new screen.
  111. ;
  112.  
  113. That is not too bad, but I left out the fun part.  Before the RefreshDesktop 
  114. there is a section named "Fix up the screen to look good."  This section is 
  115. where you might want to put some color into windows, controls, and menus if 
  116. you are switching to 320 mode; changing colors is not required, but there are 
  117. some things which are.
  118.  
  119. When switching from 640 mode to 320 mode, some windows (both visible and 
  120. invisible) might be positioned off the screen in 320 mode.  The first way to 
  121. handle this problem is easy for you, the programmer, but not so great for the 
  122. user:  close all the windows before changing modes, then position them 
  123. correctly when the user opens them in the new mode.  The second way to handle 
  124. the problem is to walk the window list and move all the windows, maybe even 
  125. change their sizes.  You could double each window's horizontal starting 
  126. position and width when switching from 320 mode to 640 mode and halve it when 
  127. changing from 640 mode to 320 mode.  The vertical position and height are 
  128. okay.  An example of the second method is given below.
  129.  
  130. Windows with vertical scroll bars in the window frame are the same width when 
  131. you change modes, so switching from 320 mode to 640 mode results in a narrower 
  132. bar while changing from 640 mode to 320 mode produces a wider bar.  The bars 
  133. change to the correct size as soon as the user resizes the window, since 
  134. SizeWindow deletes the old scroll bars and allocates new ones according to the 
  135. current mode.  If, as suggested above, you resize all the windows after the 
  136. mode change and before calling RefreshDesktop, you should be in good shape.  
  137. If you choose not the follow this recommendation, you should call SizeWindow 
  138. for every window with scroll bars and change the size of each window at least 
  139. one pixel since SizeWindow does not do anything if the passed size is not 
  140. different than the current size.
  141.  
  142. You should dispose of scroll bars in a window's content region and recreate 
  143. them; this is not nice, but very few applications have scroll bars in a 
  144. window's content region.
  145.  
  146. You should not resize any open new desk accessory (NDA) windows.  NDAs may be 
  147. dependent on screen mode, or their current position, or other such things 
  148. which may change with resolution.  To be kind to the NDAs, you should issue a 
  149. CloseAllNDAs call.  This call allows the NDAs to go through their normal close 
  150. procedures.  If a user wants an NDA open in the new screen resolution he must 
  151. reopen it.  This assures that the NDA always knows its own position and the 
  152. current screen resolution.
  153.  
  154. WindNewRes resets the desktop shape and pattern and the Window Manager's icon 
  155. font to their defaults for the new mode, so if you changed any of these, you 
  156. must add to or subtract from the desktop again and reinitialize to your custom 
  157. pattern or icon font again.
  158.  
  159. CtlNewRes resets the Control Manager's icon font to the default for the new 
  160. mode, so if you changed the Control Manager's icon font, you must reinitialize 
  161. to your icon font again.
  162.  
  163.  
  164. Repositioning and Resizing Windows in the New Mode
  165.  
  166. Here is an example of how to reposition and resize windows in the new mode.
  167.  
  168. ;    QuickDraw and the tools have already been reinitialized in the new mode.
  169. ;    mode = $0000 if in 320 mode, $0080 if in 640 mode.
  170. ;
  171. BoundsRect   equ 8              ;Offsets in port record from QuickDraw document
  172. PortRect     equ 16
  173. ;
  174.              _CloseAllNDAs      ; close all open NDA windows
  175.              pha                ;Space for result.
  176.              pha
  177.              _FrontWindow       ;Start with the top most window, this assumes
  178.              bra enter          ;there are no invisible windows ahead of the
  179.                                 ;active window in the window list.
  180.              ldy #BoundsRect+2
  181.              lda [window],y     ;Get window's starting horizontal position.
  182.              eor #$FFFF         ;Convert to screen coordinate (negate it).
  183.              inc a
  184.              asl a              ;Double it if we're going to 640 mode.
  185.              ldx <mode          ;Going to 320 or 640 mode?
  186.              bne store1         ;Ready if we're going to 640.
  187.              lsr a              ;Otherwise, undo the doubling,
  188.              lsr a              ;and halve the starting horizontal position.
  189.  
  190. store1       pha                ;Pass window's new X starting position.
  191.              ldy #BoundsRect
  192.              lda [window],y     ;Get window's starting vertical position.
  193.              eor #$FFFF         ;Convert to screen coordinate.
  194.              inc a
  195.              pha                ;Pass window's current Y starting position.
  196.              pei <window+2      ;Pass window to move.
  197.              pei <window
  198.              _MoveWindow        ;Move the window to its new position.
  199. ;
  200.              ldy #PortRect+6    ;Get window's current width.
  201.              lda [window],y     ;(This assumes the window's origin is 0,0.)
  202.              asl a              ;Double the window's width if going to 640 mode
  203.              ldx <mode          ;Going to 320 or 640 mode?
  204.              bne store2         ;Ready if we're going to 640.
  205.              lsr a              ;Otherwise, undo the doubling,
  206.              lsr a              ;and halve the window's width.
  207. store2       pha                ;Pass window's new width.
  208.              ldy #PortRect+4
  209.              lda [window],y     ;Get window's height.
  210.              pha                ;Pass window's current height.
  211.              pei <window+2      ;Pass window to resize.
  212.              pei <window
  213.              _SizeWindow        ;Resize the window.
  214. ;
  215.              pha                ;Space for result.
  216.              pha
  217.              pei <window+2      ;Pass pointer to window we just processed.
  218.              pei <window
  219.              _GetNextWindow     ;Get the pointer to the next window.
  220. ;
  221. enter        pla                ;Remember the pointer to this window.
  222.              sta <window
  223.              pla
  224.              sta <window+2
  225. ;
  226.              ora <window        ;Are there any more windows?
  227.              bne loop
  228. ;
  229.  
  230. WindNewRes
  231.  
  232. Generally, WindNewRes does the following:
  233.  
  234.   o  closes its port
  235.   o  opens its port again, now in the new mode
  236.   o  reinitializes the desktop size
  237.   o  chooses the proper icon font for close and zoom boxes
  238.   o  reinitializes the desktop pattern
  239.   o  changes the SCB byte of each window's port to the new mode
  240.   o  recomputes the VisRgn for each window
  241.  
  242. MenuNewRes
  243.  
  244. Generally, MenuNewRes does the following:
  245.  
  246.   o  closes its port
  247.   o  opens its port again, now in the new mode
  248.   o  reinitializes internal parameters, like vertical line width, for the new 
  249.      mode
  250.   o  reinitializes the color palette via InitPalette
  251.   o  subtracts the system menu bar from the desktop (this is why you must call 
  252.      WindNewRes first)
  253.   o  draws the system menu bar
  254.  
  255. CtlNewRes
  256.  
  257. Generally, CtlNewRes does the following:
  258.  
  259.   o  chooses the proper icon font for radio button, check box, grow box and 
  260.      scroll bar arrows
  261.   o  reinitializes internal parameters, like vertical line width, for the new 
  262.      mode
  263.  
  264.